﻿<Window x:Class="StackHash.ProfileManager"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:StackHash"
    xmlns:vcs="clr-namespace:StackHash.ValueConverters"
    Title="Service Options - StackHash" Height="450" MinHeight="450" Width="400" MinWidth="400" WindowStartupLocation="CenterOwner" Icon="/StackHash;component/StackHash.ico" ShowInTaskbar="False"   ResizeMode="CanResize" Loaded="Window_Loaded" Closed="Window_Closed">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="MasterResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding Command="Help" x:Name="commandBindingHelp" Executed="commandBindingHelp_Executed" />
    </Window.CommandBindings>
    <Grid IsEnabled="{Binding NotBusy}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <TabControl Margin="10" Name="tabControl">
            <TabItem Header="Profiles" Name="tabItemProfiles">
                <AdornerDecorator>
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <Border Margin="3" Grid.ColumnSpan="2" BorderBrush="Black" BorderThickness="1" Background="LightYellow">
                            <TextBlock Margin="3" TextWrapping="Wrap">
                                Editing a profile will cause it to be deactivated and then reactivated. 
                                This will interrupt any users currently working with the profile.
                                Set the profile used by the StackHash Client in Tools -> Client Options.
                            </TextBlock>
                        </Border>

                        <ListView Margin="3" Grid.Row="1" ItemsSource="{Binding ContextCollection}" SelectionMode="Single" Name="listViewProfiles" MouseDoubleClick="listViewProfiles_MouseDoubleClick" SelectionChanged="listViewProfiles_SelectionChanged" GridViewColumnHeader.Click="listViewProfiles_Click">
                            <ListView.ItemContainerStyle>
                                <Style TargetType="ListViewItem">
                                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                </Style>
                            </ListView.ItemContainerStyle>
                            <ListView.View>
                                <GridView>
                                    <GridViewColumn Width="85">
                                        <GridViewColumnHeader Tag="ProfileName" Content="Profile Name" />
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding ProfileName}" ToolTip="{Binding IdText}" HorizontalAlignment="Left" />
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Width="95">
                                        <GridViewColumnHeader Tag="IsActive" Content="Active (Will Sync)" />
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <CheckBox IsChecked="{Binding IsActive, Mode=OneTime}" HorizontalAlignment="Center" Checked="ProfileActive_Checked" Unchecked="ProfileActive_Unchecked" />
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                    <GridViewColumn Width="50">
                                        <GridViewColumnHeader Tag="CurrentErrorText" Content="Status" />
                                        <GridViewColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding CurrentErrorText}" HorizontalAlignment="Left" ToolTip="{Binding CurrentErrorText}" />
                                            </DataTemplate>
                                        </GridViewColumn.CellTemplate>
                                    </GridViewColumn>
                                </GridView>
                            </ListView.View>
                        </ListView>

                        <StackPanel Margin="0" Grid.Row="1" Grid.Column="1" Orientation="Vertical" VerticalAlignment="Top">
                            <Button Margin="3" Name="buttonAdd" Click="buttonAdd_Click" PreviewMouseDown="buttonAdd_PreviewMouseDown" ToolTip="Add a new profile.">
                                <StackPanel Orientation="Horizontal">
                                    <Image Margin="0,0,5,0" VerticalAlignment="Center" Width="16" Height="16" Name="imageShield" />
                                    <Label Margin="-5" VerticalAlignment="Center" Target="{Binding ElementName=buttonAdd}">_Add...</Label>
                                </StackPanel>
                            </Button>
                            <Button Margin="3" Name="buttonEdit" Click="buttonEdit_Click" ToolTip="Edit a profile.">_Edit</Button>
                            <Button Margin="3" Name="buttonDelete" Click="buttonDelete_Click" ToolTip="Delete a profile.">_Delete</Button>
                            <Button Margin="3" Name="buttonTestData" Click="buttonTestData_Click" ToolTip="Add test data to a profile.">_Test Data...</Button>
                            <Button Margin="3" Name="buttonErrorDetails" Click="buttonErrorDetails_Click" ToolTip="Show detailed information for the error with the selected profile.">Show Error</Button>
                        </StackPanel>

                    </Grid>
                </AdornerDecorator>
            </TabItem>
            <TabItem Header="Proxy Server" Name="tabItemProxyServer">
                <AdornerDecorator>
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>

                        <TextBlock Margin="5,5,5,12" TextWrapping="Wrap">
                            Enter proxy server settings for the StackHash Service below. 
                            Proxy settings for the client can be found in Tools -> Options.
                        </TextBlock>

                        <local:ProxySettingsControl Grid.Row="1" x:Name="proxySettingsControl" />

                    </Grid>
                </AdornerDecorator>
            </TabItem>
            <TabItem Header="Advanced" Name="tabItemAdvanced">
                <AdornerDecorator>
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Margin="6" Grid.ColumnSpan="2" FontWeight="Bold">Client Settings:</TextBlock>

                        <Label Grid.Row="1" Target="{Binding ElementName=textBoxClientTimeout}">_Client Timeout (minutes):</Label>
                        <TextBox Margin="3" Grid.Row="1" Grid.Column="1" Name="textBoxClientTimeout" Text="{Binding ClientTimeoutInMinutes, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, Mode=TwoWay}" ToolTip="{Binding ElementName=textBoxClientTimeout, Path=(Validation.Errors)[0].ErrorContent}" />

                    </Grid>
                </AdornerDecorator>
            </TabItem>
            <TabItem Header="Troubleshooting" Name="tabItemTroubleshooting">
                <AdornerDecorator>
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                    
                        <CheckBox Margin="3" Name="checkBoxServiceLog" Checked="checkBoxServiceLog_Checked" Unchecked="checkBoxServiceLog_Unchecked">Enable StackHash Service diagnostic _log</CheckBox>
                    </Grid>
                </AdornerDecorator>
            </TabItem>
        </TabControl>

        <Border Grid.Row="1" Style="{StaticResource ButtonBorder}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                
                <Button Margin="10" Command="Help">_Help</Button>

                <StackPanel Margin="7" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
                    <Button IsDefault="True" Margin="3" Name="buttonOK" Click="buttonOK_Click">OK</Button>
                    <Button IsCancel="True" Margin="3" Name="buttonCancel" Click="buttonCancel_Click">Cancel</Button>
                </StackPanel>
            </Grid>
        </Border>
    </Grid>
</Window>
